import QtQuick 2.11
import QtQuick.Window 2.2
import Qt.labs.platform 1.0
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.3

Page{
    id:pageXmlParseConfig
    Column{
        anchors.fill: parent
        GroupBox{
            id:paneXmlConfig
            contentWidth: parent.width
            contentHeight: parent.height/2
            title: qsTr("xmlConfigView/revise")
            label: Label {
                x: parent.leftPadding
                width: parent.availableWidth
                height: 20
                font.pixelSize: 16
                font.bold: true
                text: parent.title
                color: "#000000"
                background: Rectangle{
                    anchors.fill: parent
                }
                elide: Text.ElideRight
            }
            Column{
                anchors.fill: parent
            Grid{
                width: parent.width
                rows:3;
                columns: 3;
                spacing: 10;
                bottomPadding: 20
                Button{
                    id:buttonChooseConfigFile
                    text: qsTr("Choose Config File");
                    width: 200
                    height: 30
                    onClicked: {
                        fileDialog.mission="loadConfig";
                        fileDialog.open();

                        //text = MainController.getFileName();
                        //fileDialog.mission="";
                        //MainController.loadConfig();
                    }

                }
                Label{
                    width: 100
                    height: 30
                    text:""
                }
                Label{
                    width: 100
                    height: 30
                    text:""
                }

                TextField{
                    id:inputaddFieldKey
                    width: 200
                    height: 30
                    font.family: "微软雅黑"
                    horizontalAlignment: Text.AlignRight
                    verticalAlignment: Text.AlignBottom
                    font.pixelSize: 16
                    selectByMouse: true;
                    background: Rectangle{
                        anchors.fill:parent
                        border.color: "grey"
                    }
                }

                TextField{
                    id:inputaddFieldValue
                    width: 200
                    height: 30
                    font.family: "微软雅黑"
                    horizontalAlignment: Text.AlignRight
                    verticalAlignment: Text.AlignBottom
                    font.pixelSize: 16
                    selectByMouse: true;
                    background: Rectangle{
                        anchors.fill:parent
                        border.color: "grey"
                    }
                }
                Button{
                    id:addConfig
                    text: qsTr("Add Field")
                    width: 200
                    height: 30
                    onClicked: {
                        JsonAnalyze.addField(inputaddFieldKey.text,inputaddFieldValue.text);
//                        console.log(inputaddFieldValue.text);
//                        console.log(inputaddFieldKey.text);
                    }
                }

                ComboBox {
                    id: comboBox2
                     width: 200;
                     height: 30

                    model: keyComboModel.comboList
                    onActivated: {
                        console.log("keyComboModel activated" + comboBox2.currentIndex);
                        keyComboModel.currentIndex = comboBox2.currentIndex;

                     }

                }
                Button{
                    id:buttonDeleteConfig
                    text:qsTr("Delete Config");
                    width: 200
                    height: 30
                    onClicked: {
                        JsonAnalyze.deleteConfig(comboBox2.currentIndex);
                    }

                }
            }

            Grid{
                rows:3;
                columns: 3;
                spacing: 10;
                TextField{
                    id:inputReviseFieldKey
                    width: 200
                    height: 30
                    font.family: "微软雅黑"
                    horizontalAlignment: Text.AlignRight
                    verticalAlignment: Text.AlignBottom
                    font.pixelSize: 16
                    selectByMouse: true;
                    background: Rectangle{
                        anchors.fill:parent
                        border.color: "grey"
                    }
                }
                TextField{
                    id:inputReviseFieldValue
                    width: 200
                    height: 30
                    font.family: "微软雅黑"
                    horizontalAlignment: Text.AlignRight
                    verticalAlignment: Text.AlignBottom
                    font.pixelSize: 16
                    selectByMouse: true;
                    background: Rectangle{
                        anchors.fill:parent
                        border.color: "grey"
                    }
                }
                Button{
                    id:buttonUpdateConfig
                    text:qsTr("Update Config");
                    width: 200
                    height: 30
                    onClicked: {
                        JsonAnalyze.reviseConfig(comboBox2.currentIndex,inputReviseFieldKey.text,inputReviseFieldValue.text);
                    }
                }
            }

            ComboBox {
                id: comboBox1
                 width: 200;
                 height: 30

                model: sectionComboModel.comboList
                onActivated: {
                    console.log("sectionComboModel activated" + comboBox1.currentIndex);
                    sectionComboModel.currentIndex = comboBox1.currentIndex;
                    JsonAnalyze.insertKeyAndValue(currentIndex);
                 }

            }
            CustomedTableview{
                id:tableXmlConfig
                model: JsonTable
                width: parent.width;
                height: 200;
                highlightOnFocus: true
                onSelectionChanged: {
                    selection;
                }
            }
            }
            background: Rectangle{
                anchors.fill: parent
//                border.color: "black"
                
            }
        }
        GroupBox{
            id:paneXmlReadTest
            contentWidth: parent.width
            title: qsTr("xmlTestRecord")
            
            label: Label {
                x: parent.leftPadding
                width: parent.availableWidth
                height: 20
                font.pixelSize: 16
                font.bold: true
                text: parent.title
                color: "#000000"
                background: Rectangle{
                    anchors.fill: parent
                }
                elide: Text.ElideRight
            }
            Column{
                anchors.fill: parent

                Grid{
                    width: parent.width
                    rows:3;
                    columns: 3;
                    spacing: 10;
                    bottomPadding: 20
                    Button{
                        id:buttonChooseTestXmlFile
                        text: qsTr("Choose XMl File");
                        width: 200
                        height: 30
                        onClicked: {
                            fileDialog.mission="loadRecord";
                            fileDialog.open();
                            JsonAnalyze.writeJson();
                            //MainController.loadConfig();
                        }

                    }
                }
                CustomedTableview{
                    id:tableTestXmlRecord
                    width: parent.width;
                    height: 200;
                }
            }


            background: Rectangle{
                anchors.fill: parent
                border.color: "#00070606"
                
            }
        }
        
    }

    function adjustJsonButton(textstring){
        buttonChooseConfigFile.text = textstring;
    }

    function adjustXmlButton(textstring){
        buttonChooseTestXmlFile.text = textstring;
    }

    Component.onCompleted: {
        tableXmlConfig.initColumns([{"title":"key","role":"title01"},{"title":"value","role":"title02"}]);//,{"title":"col1","role":"title03"},{"title":"col2","role":"title04"}]);

        tableTestXmlRecord.initColumns([{"title":"col0","role":"title01"},{"title":"col0","role":"title02"},{"title":"col1","role":"title03"},{"title":"col2","role":"title04"}])
    }
}
